﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>
<%@ Import Namespace="TarreOA.TarreOAModels  " %>

<script runat="server">

    private string linkManUnitName;

    protected void DataList_DataTable(List<UserCommunicationGroupLinkMantb> list)
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        dt.Columns.Add("GroupLinkManId", typeof(string));
        dt.Columns.Add("GroupLinkManName", typeof(string));
        dt.Columns.Add("GroupLinkManHandset", typeof(string));
        dt.Columns.Add("GroupLinkManSec", typeof(string));
        dt.Columns.Add("GroupLinkManUnitTelephone", typeof(string));
        dt.Columns.Add("GroupLinkManEmail", typeof(string));
        foreach(UserCommunicationGroupLinkMantb ucgLinkMan in list)
        {
            DataRow dr = dt.NewRow();
            dr["GroupLinkManId"] = ucgLinkMan.GroupLinkManId.ToString();
            dr["GroupLinkManName"] = ucgLinkMan.GroupLinkManName;
            dr["GroupLinkManHandset"] = ucgLinkMan.GroupLinkManHandset;
            dr["GroupLinkManSec"] = ucgLinkMan.GroupLinkManSec == 0 ? "男" : "女";
            dr["GroupLinkManUnitTelephone"] = ucgLinkMan.GroupLinkManUnitTelephone;
            dr["GroupLinkManEmail"] = ucgLinkMan.GroupLinkManEmail;
            dt.Rows.Add(dr);
        }
        ds.Tables.Add(dt);
        this.DataList1.DataSource = ds.Tables[0].DefaultView;
        this.DataList1.DataBind();
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string cgLinkManId = ((HtmlInputHidden) e.Item.FindControl("HidLinkManId")).Value;
            ((HyperLink) e.Item.FindControl("HylInfo")).Attributes.Add("cgLinkManId", cgLinkManId);
            ((HyperLink) e.Item.FindControl("HylInfo")).NavigateUrl = "javascript:openLinkManInfoDialogWindow('" + cgLinkManId + "')";
            //((HyperLink)e.Item.FindControl("HylEdit")).Attributes.Add("cgLinkManId", cgLinkManId);
            ((HyperLink) e.Item.FindControl("HylEdit")).NavigateUrl = "UpdateGroupLinkManInfo.aspx?cgLmid=" + cgLinkManId;
            ((LinkButton) e.Item.FindControl("LbtDelete")).Attributes.Add("cgLinkManId", cgLinkManId);
            ((LinkButton) e.Item.FindControl("LbtDelete")).Attributes.Add("onclick", "return confirm('您确认删除此联系人吗？')");
        }
    }

    protected void LbtDelete_Click(object sender, EventArgs e)
    {
        if(ViewState["linkManUnitName"] != null)
        {
            linkManUnitName = (string) ViewState["linkManUnitName"];
        }
        User curLoginUser = (User) Session["user"];
        int cgLinkManId = int.Parse(((LinkButton) sender).Attributes["cgLinkManId"]);
        UserCommunicationGroupLinkMantbService ucgLinkManService = new UserCommunicationGroupLinkMantbService();
        ucgLinkManService.delComGroupLinkManByGroupLinkManId(cgLinkManId);
        this.FindUserLinkMan(linkManUnitName);
        ViewState["linkManUnitName"] = linkManUnitName;
    }

    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        linkManUnitName = this.TxtLinkManUnitName.Text;
        this.FindUserLinkMan(linkManUnitName);
        ViewState["linkManUnitName"] = linkManUnitName;
    }

    protected void FindUserLinkMan(string linkManUnitName)
    {
        User curLoginUser = (User) Session["user"];
        UserCommunicationGroupLinkMantbService ucgLinkManService = new UserCommunicationGroupLinkMantbService();
        List<UserCommunicationGroupLinkMantb> list = ucgLinkManService.findByLinkManUnitNameAndUserLoginName(linkManUnitName, curLoginUser.LoginName);
        if(list != null && list.Count > 0)
        {
            this.DataList_DataTable(list);
        }
        else
        {
            this.DataList1.DataSource = null;
            this.DataList1.DataBind();
        }
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <link rel="Stylesheet" type="text/css" href="../../Styles/right_style.css" />
    <script type="text/javascript" src="../../js/UserCommunication.js"></script>
        <script type="text/javascript" src="../../Scripts/jquery.ui/js/jquery.js"></script>

    <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>

</head>
<body>
    <form id="form1" runat="server">
       <div class="sub_right_top" align="center">
                <table width="97%" border="1" cellpadding="0" cellspacing="0" bordercolor="#72b0d8" style="border-collapse:collapse; ">
          <tr bgcolor="#b1d5ef">
            <td colspan="2" align="center">查找联系人</td>
          </tr>

          <tr>
            <td width="120">单位名称关键字:</td>
            <td>
            <div class="disk_queding_top"><asp:TextBox ID="TxtLinkManUnitName" runat="server" Width="182px"></asp:TextBox></div>
            <div class="disk_liulan_tow">
                    <asp:Button ID="ImageButton1"  runat="server" OnClick="ImageButton1_Click" OnClientClick="return checkFindLinkManByName('TxtLinkManName')" CssClass="press_set_button"/>
            </div>            
            </td>
          </tr>
        </table>
        <div style="height:5px; overflow:hidden;"></div>
            <asp:Repeater ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
                             <HeaderTemplate>
                                     <table width="97%" border="1" cellpadding="0" cellspacing="0" bordercolor="#72b0d8" style="border-collapse:collapse; ">
                                    <tr bgcolor="#b1d5ef">
                                        <td width="80" align="center">姓名</td>
                                        <td width="30" align="center">性别</td>
                                        <td width="85" align="center">单位电话</td>
                                        <td width="85" align="center">手机号码</td>
                                        <td align="center">电子邮件</td>
                                        <td width="90" align="center">操作</td>
                                      </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                    <tr >
                                        <td>
                                            <asp:Label ID="LblLinkManName" runat="server" Text='<%# Eval("GroupLinkManName") %>'></asp:Label></td>
                                        <td>
                                            <asp:Label ID="LblLinkManSec" runat="server" Text='<%# Eval("GroupLinkManSec") %>' ></asp:Label></td>
                                        <td>
                                            <asp:Label ID="LblLinkManUnitTelephone" runat="server" Text='<%# Eval("GroupLinkManUnitTelephone") %>' ></asp:Label></td>
                                        <td>
                                            <asp:Label ID="LblHandset" runat="server" Text='<%# Eval("GroupLinkManHandset") %>' ></asp:Label></td>
                                        <td>
                                            <asp:Label ID="LblLinkManEmail" runat="server" Text='<%# Eval("GroupLinkManEmail") %>' ></asp:Label>
                                            <input id="HidLinkManId" runat="server" type="hidden" value='<%# Eval("GroupLinkManId") %>' />
                                        </td>
                                        <td>
                                            <asp:HyperLink ID="HylInfo" runat="server"
                                                Font-Underline="false" ForeColor="#C04000">详情</asp:HyperLink>
                                            <asp:HyperLink ID="HylEdit" runat="server" 
                                                Font-Underline="false" ForeColor="#C04000">编辑</asp:HyperLink>
                                            <asp:LinkButton ID="LbtDelete" runat="server" Font-Underline="False" ForeColor="#C04000" OnClick="LbtDelete_Click">删除</asp:LinkButton></td>
                                    </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>
        </div>
    </form>
</body>
</html>
